//
// Created by work on 24-6-6.
//

#include "iot_model_device/CRtModelYcInfo.h"
namespace iotplat {
    std::map<CRtModelYcInfo::EModelYcCol, std::string> CRtModelYcInfo::rtModelYcColToStringMap = {
            {CRtModelYcInfo::EBase, "base"},
            {CRtModelYcInfo::ECoef, "coef"},
            {CRtModelYcInfo::EEn_alarm, "en_alarm"},
            {CRtModelYcInfo::EAlarm_up_limit, "alarm_up_limit"},
            {CRtModelYcInfo::EAlarm_down_limit, "alarm_down_limit"},
            {CRtModelYcInfo::EAlarm_up_limit_desc, "alarm_up_limit_desc"},
            {CRtModelYcInfo::EAlarm_down_limit_desc, "alarm_down_limit_desc"},
            {CRtModelYcInfo::EAlarm_time_count, "alarm_time_count"}
    };

    std::map<CRtModelYcInfo::EModelYcCol, CValue::EValueType> CRtModelYcInfo::rtYcDataTypeByField = {
            {CRtModelYcInfo::EBase, CValue::IOT_Float},
            {CRtModelYcInfo::ECoef, CValue::IOT_Float},
            {CRtModelYcInfo::EEn_alarm, CValue::IOT_Bool},
            {CRtModelYcInfo::EAlarm_up_limit, CValue::IOT_Float},
            {CRtModelYcInfo::EAlarm_down_limit, CValue::IOT_Float},
            {CRtModelYcInfo::EAlarm_up_limit_desc, CValue::IOT_String},
            {CRtModelYcInfo::EAlarm_down_limit_desc, CValue::IOT_String},
            {CRtModelYcInfo::EAlarm_time_count, CValue::IOT_Int}
    };

    CRtModelYcInfo::CRtModelYcInfo() {
    }

    void CRtModelYcInfo::fromJson(Json::Value json) {
        model_name = json[baseSigFieldName(BASE_SIG_ENUM::EModel_name)].asString();
        user = json[baseSigFieldName(BASE_SIG_ENUM::EUser)].asString();
        name = json[baseSigFieldName(BASE_SIG_ENUM::EName)].asString();
        descr = json[baseSigFieldName(BASE_SIG_ENUM::EDescr)].asString();
        sn = json[baseSigFieldName(BASE_SIG_ENUM::ESn)].asInt();
        grouping = json[baseSigFieldName(BASE_SIG_ENUM::EGrouping)].asString();
        configs = json[baseSigFieldName(BASE_SIG_ENUM::EConfigs)];
        base = json[ycFieldName(YC_ENUM::EBase)].asFloat();
        coef = json[ycFieldName(YC_ENUM::ECoef)].asFloat();
        en_alarm = json[ycFieldName(YC_ENUM::EEn_alarm)].asBool();
        alarm_up_limit = json[ycFieldName(YC_ENUM::EAlarm_up_limit)].asFloat();
        alarm_down_limit = json[ycFieldName(YC_ENUM::EAlarm_down_limit)].asFloat();
        alarm_up_limit_desc = json[ycFieldName(YC_ENUM::EAlarm_up_limit_desc)].asString();
        alarm_down_limit_desc = json[ycFieldName(YC_ENUM::EAlarm_down_limit_desc)].asString();
        alarm_time_count = json[ycFieldName(YC_ENUM::EAlarm_time_count)].asInt();
    }

    Json::Value CRtModelYcInfo::toJson() {
        Json::Value json;
        json[baseSigFieldName(BASE_SIG_ENUM::EModel_name)] = model_name;
        json[baseSigFieldName(BASE_SIG_ENUM::EUser)] = user;
        json[baseSigFieldName(BASE_SIG_ENUM::EName)] = name;
        json[baseSigFieldName(BASE_SIG_ENUM::EDescr)] = descr;
        json[baseSigFieldName(BASE_SIG_ENUM::ESn)] = Json::Value(sn);
        json[baseSigFieldName(BASE_SIG_ENUM::EGrouping)] = grouping;
        json[baseSigFieldName(BASE_SIG_ENUM::EConfigs)] = configs;

        json[ycFieldName(YC_ENUM::EBase)] = base;
        json[ycFieldName(YC_ENUM::ECoef)] = coef;
        json[ycFieldName(YC_ENUM::EEn_alarm)] = en_alarm;
        json[ycFieldName(YC_ENUM::EAlarm_up_limit)] = alarm_up_limit;
        json[ycFieldName(YC_ENUM::EAlarm_down_limit)] = alarm_down_limit;
        json[ycFieldName(YC_ENUM::EAlarm_up_limit_desc)] = alarm_up_limit_desc;
        json[ycFieldName(YC_ENUM::EAlarm_down_limit_desc)] = alarm_down_limit_desc;
        json[ycFieldName(YC_ENUM::EAlarm_time_count)] = Json::Value(alarm_time_count);
        return json;
    }
} // iotplat